package eerbaar.action.internal.lib;

import java.util.Map;

import eerbaar.context.IContext;
import eerbaar.context.IParams;
import eerbaar.context.ParamFactory;
import eerbaar.message.lib.DisplayMessageMsg;
import eerbaar.shared.message.MsgHelper;

public class DisplayMessageAction extends AbstractAction {

    private String message;

    private IParams params;

    public DisplayMessageAction() {
        super("displayMessage");

        this.params = ParamFactory.createParams();
    }

    public DisplayMessageAction(IParams params) {
        super("displayMessage");
        this.params = params;

        setup(params);
    }

    @Override
    public void execute(IContext model) {

        MsgHelper.sendMsg(DisplayMessageMsg.class, new DisplayMessageMsg(
                this.message));
    }

    @Override
    public void execute(IContext model, Map<String, String> map) {
        execute(model);
    }

    @Override
    public String[] getParamNames() {

        return new String[] { "message" };
    }

    @Override
    public IParams getParams() {

        return this.params;
    }

    @Override
    public void setParams(IParams params) {

        this.params = params;
        setup(params);
    }

    private void setup(IParams params) {

        this.message = params.get("message");
    }

}
